fix: thread agenthub_config through chat_model_factory new path#834
Closed
cotovanu-cristian wants to merge 1 commit intomainfrom
Closed
fix: thread agenthub_config through chat_model_factory new path#834cotovanu-cristian wants to merge 1 commit intomainfrom
cotovanu-cristian wants to merge 1 commit intomainfrom
Conversation
PlatformSettings.agenthub_config defaults to "agentsruntime" upstream. The local _AgentHubConfigDefaultMixin clears this default for direct chat-model construction (UiPathChat, UiPathChatOpenAI, etc.), but the factory path used by uipath-agents bypassed the mitigation entirely: get_chat_model accepted agenthub_config but its docstring said it was "ignored by the new factory" — and indeed it was, dropped on the floor before delegating to the upstream factory. Result: agents running with command="debug" computed agenthub_config="agentsplayground" via get_agenthub_config(...) and passed it to get_chat_model, but every LLM gateway request shipped X-UiPath-AgentHub-Config: agentsruntime — billing the runtime quota instead of the developer debug quota. Fix: when agenthub_config is provided on the new path, build a client_settings (via get_default_client_settings) if absent and set client_settings.agenthub_config before delegating. Caller-supplied client_settings instances are mutated rather than replaced so other fields survive. Pass-through preserved when agenthub_config is None to leave existing env-var / direct-construction paths governed by the mixin. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
closing as it's included in #835 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When agents run with
command=\"debug\"(or any non-runtime context), the LLM gateway calls were shippingX-UiPath-AgentHub-Config: agentsruntimeinstead of the computedagentsplayground. Every debug session was billed against the runtime quota.The bug
chat_model_factory.get_chat_modelaccepted anagenthub_configparameter whose docstring said it was "ignored by the new factory" — and it was. On theuse_new_llm_clients=Truepath, the value was dropped before delegating touipath_langchain_client.factory.get_chat_model, which built a freshPlatformSettingswhoseagenthub_configdefaults to\"agentsruntime\"upstream.The local
_AgentHubConfigDefaultMixin(added in #825/#830) clears that default for direct-construction users —from uipath_langchain.chat import UiPathChatetc. — but the factory path bypassed it entirely, souipath-agentscallers inagent_graph_builder/llm_utils.py:create_llmhad their carefully computed value silently discarded.Trace for
uipath debug agent.json:The fix
In
chat_model_factory.get_chat_model, whenagenthub_configis provided on the new path:client_settingsviaget_default_client_settings()if the caller didn't supply one.client_settings.agenthub_config = agenthub_configbefore delegating.client_settingsinstances are mutated, not replaced, so other fields survive.agenthub_config=Noneis a pass-through — preserves existing env-var / direct-construction paths governed by the mixin.hasattrguard mirrors the pattern in_AgentHubConfigDefaultMixin._clear_agenthub_config_default, since theUiPathBaseSettingsABC doesn't exposeagenthub_config(only the concretePlatformBaseSettingsdoes).What changed
src/uipath_langchain/chat/chat_model_factory.pytests/chat/test_chat_model_factory_agenthub.pypyproject.tomluv.lockTests added (4)
get_chat_model(agenthub_config=\"agentsplayground\", use_new_llm_clients=True)results inclient_settings.agenthub_config == \"agentsplayground\"reaching the upstream factory. Was failing before the fix; proves the bug.agenthub_config=Nonedoes not synthesize aclient_settings; preserves env-var / mixin paths.client_settingsis mutated, not replaced; non-agenthub_configfields survive.use_new_llm_clients=Falsestill threadsagenthub_configto the legacy factory.Existing
tests/chat/test_agenthub_config_default.py(39 tests for direct-construction mixin behavior) still passes — the fix is additive, the mixin is still load-bearing for direct constructors.Full chat suite: 239 passed.
Out of scope / follow-ups
ClaudeSDKRuntimeandGatewayProxydefaults inuipath-agents-python/src/uipath_agents/claude_sdk/{runtime.py:90,gateway_proxy.py:168}— sameagenthub_config: str = \"agentsruntime\"anti-pattern. Currently masked byAgentsClaudeSDKRuntimeoverriding both. Worth fixing but lives in a different repo/package.PlatformSettings.agenthub_config = \"agentsruntime\"default inuipath_langchain_client— would be a cleaner fix to setdefault=Noneupstream, but cross-package coordination. This PR neutralizes the symptom for the agents path without needing it.Test plan
uv run pytest tests/chat/test_chat_model_factory_agenthub.pyuv run pytest tests/chat/test_agenthub_config_default.pyuv run pytest tests/chat/(239 passed)uv run mypy src/uipath_langchain/chat/chat_model_factory.pyuv run uipath debug agent.json '{}'against a real tenant; confirm LLM gateway requests carryX-UiPath-AgentHub-Config: agentsplayground🤖 Generated with Claude Code